<!--
	作者：956911785@qq.com
	时间：2019年9月14日17:38:54
	描述：诗词作业检查人员-添加
-->

<template>
	<Modal :title="title" v-model="modal0" width="800px">
		<Form ref="params" :label-width="120" label-position="left">
			<div style="width:100%;min-height:300px;max-height:600px; overflow-y: scroll;">
		      	
				<div style="width:100%;height:40px;line-height: 40px;float:left;text-align: left;">
	        		<div style="width:80%;float:left;">
		      			<FormItem  prop="readid" label="诗词">
				        	<Select v-model="readid" style="width:200px" clearable>
						        <Option v-for="item in poetrys" :value="item.READID" :key="item.PNAME">{{ item.PNAME }}</Option>
						    </Select>
		        		</FormItem>
		      		</div>
		      		<div style="width:40px;float:left;">
		      			<Icon type="md-add" size="30" title="新增" style="cursor: pointer;margin-right:5px;color:#42B983;" @click="addPoetry()"/>
	      			</div>
		      	</div>
		      	
		      	<template v-for="(item,index) in reads">
			      	<div style="width:100%;float:left;text-align: left;background: #E8E8E8;margin-top:10px;">
			      		<div style="width:100%;float:left;height:40px;line-height: 40px;">
			      			<div style="width:80%;float:left;">
				      			<FormItem label="日期" >
									<DatePicker v-model="item.riqi" transfer type="datetime" format="yyyy-MM-dd" placeholder="请选择负责检查的日期" style="width:80%"></DatePicker>
								</FormItem>
				      		</div>
							<div style="width:50px;float:left;">
								<Icon type="md-close" size="20" title="删除" style="cursor: pointer;margin-right:5px;color:#CD3333;" @click="delPoetry(index)"/>
							</div>
				      		<div style="width:50px;float:left;">
				      			<Icon type="md-add-circle" size="20" title="新增" style="cursor: pointer;margin-right:5px;color:#42B983;" @click="addZh(index)"/>
			      			</div>
			      		</div>
			      		
						<FormItem  label="负责检查的账号">
							<template v-for="(zitem,zindex) in item.zh">
								<div style="width:38%;float:left;height:40px;line-height: 40px;padding-right:2%;">
									<div style="width:90%;float:left;">
										<Input v-model="zitem.dlzh" placeholder="请填写检查人员的账号" clearable style="width: 100%"></Input>
									</div>
									<div style="width:10%;float:left;">
										<Icon type="md-close-circle" size="20" title="删除" style="cursor: pointer;margin-right:5px;color:#CD3333;" @click="delZh(index,zindex)"/>
									</div>
								</div>
							</template>
						</FormItem>
			      	</div>
		      	</template>
		      	
		   </div> 
	    </Form>
	   	<div slot="footer">
	    	<Button type="text"  @click="closeModal()">取消</Button>
	    	<Button type="primary" @click="addsave()" >确定</Button>
	    </div>
     </Modal>
</template>

<script>

	
	export default {
		name:"tconent",
		props: {
    		title:{
    			type:String,	
    		},
    	},
		data() {
			return {   
                modal0:false,
                num:1,
            	poetrys:[],
            	readid:'',
            	reads:[
            		{
            			riqi:null,
						weekday:'',
            			zh:[
            				{dlzh:''}
            			]
            		}
            	]
			} 
		},
		methods: {
			addsave:function(){
				var readid=this.readid;
				if(readid==""){
					this.$Modal.error({
					    title: "提示",
					    content:"请选择诗词！"
					});	
					return;
				}
				
				var reads=this.reads;
				var readarr=[];
				for(var i=0;i<reads.length;i++){
					var read=reads[i];
					if(read.riqi){
						var riqi=this.getNowFormatDate(read.riqi);
						var weekday=read.riqi.getDay();
						var readstr={
							riqi:riqi,
							weekday:weekday,
							zh:read.zh
						};
						readarr.push(readstr);
					}
				}
				
				var params={
					readid:readid,
					reads:JSON.stringify(readarr)
				}
				this.$emit("addsave",params);
	        }, 
            closeModal(){
	      	    this.modal0 = false;
	        },
			
			getAllPoetryRead(){	
				this.$http.get("/host/readbook/poetryread/getAllPoetryRead.html")
				.then(result => {	
					this.poetrys=result;
				});
			},
			
			addPoetry(n){
            	var readstr={
					riqi:null,
					weekday:'',
        			zh:[
        				{dlzh:''}
        			]           		
            	}
            	var reads=this.reads;
            	reads.push(readstr);
				this.reads=reads;
			},
			
			delPoetry(n){
				var reads=this.reads;
				reads.splice(n,1);
			},	
			
			addZh(n){
            	var readarr=[];
				var reads=this.reads;
				for(var m=0;m<reads.length;m++){
					var read=reads[m];
					if(m==n){
						var zh=read.zh;
						var zhstr={
							dlzh:''
						}
						zh.push(zhstr);
					}
				}
			},
			
			
			delZh(index,zindex){
            	var readarr=[];
				var reads=this.reads;
				var read=reads[index];
				var zh=read.zh;
				zh.splice(zindex,1);
			},
			
			getNowFormatDate(date) {
				var seperator1 = "-";
				var month = date.getMonth() + 1;
				var strDate = date.getDate();
				if (month >= 1 && month <= 9) {
					month = "0" + month;
				}
				if (strDate >= 0 && strDate <= 9) {
					strDate = "0" + strDate;
				}
				var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
				return currentdate;
			}
		},
		mounted() {
			//查询诗词
			this.getAllPoetryRead();
		},
		watch:{
			modal0(news,olds){

			}
		},
		computed: {
		
		}
		
	}
</script>

<style scoped="scoped">
	
</style>



